_Pragma("once")

#include <string>
#include <ctime>

#include "TaskScheduler.h"
#include "SingletonTemplate.h"

class ConfigManager;

class Authenticator
{
    friend class SingletonTemplate<Authenticator>;
    public:
        /** Default constructor */
        Authenticator();
        /** Default destructor */
        ~Authenticator();

        virtual bool authenticate(const std::string& verifyCode);

        virtual bool authenticate(const std::time_t seconds);

        const std::string generateVerifyCode(void);

        void recoverPermit();


    volatile bool mpermit;
    protected:

    void setAutoRecover(void){
        const std::time_t timePointSecond = std::time(nullptr) + 300;
        mscheduler.makeOnlyOneTask(mwptrTaskRecord, new TaskRecord(TaskletInfo{std::bind(&Authenticator::recoverPermit, this), nullptr}, DateTimeUtility::ClockTime_t(timePointSecond * DateTimeUtility::ClockTime_t::period::den)));
    }

    TaskRecordPtr::weak_type mwptrTaskRecord;

    TaskScheduler& mscheduler;
    ConfigManager& mconfigManager;

};


